<?php
//has_openid方法，无传参，用于验证和获取openid
function has_openid(){
	session_start();
	$code  = I('get.code');
	if($code){
		$appid = C('APPID');
		$secret= C('SECRET');
		$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$code."&grant_type=authorization_code";
		$token = json_decode(curl_get_contents($url));
		print_r($token);
		exit;
	}

	$openID=I('session.OpenID');
	if(empty($openID)){
		$url = U('Index/getCode','','',true);
		header("Location:".$url);
	}else{
		echo "OK";
	}
}